<?php

	/**
	 * @see Bike_Js_Func
	 */
	require_once 'Bike/Js/Func.php';
	
	
	class Bike_Js_ResponseHandler extends Bike_Js_Func
	{
		protected function initDefaultSettings()
		{
			parent::initDefaultSettings();
			
			$js = $this->js();
			$this->setSettings(array(
				'args' => array($js->response),
				'bodyPrepend' => '',
				'bodyAppend' => '',
				'bodyDebugCode' => $js->alert($js->response->responseText),
				/*'bodyDebugCode' => $js->for($js->Ex($js->i)
												->_in($js->response))
										->_body($js->alert($js->Ex($js->i)
																->_add(' => ')
																->_add($js->response[$js->i]))),*/
			));
		}

		public function getOmitSettings()
		{
			return array_merge(parent::getOmitSettings(), array('bodyPrepend', 'bodyAppend'));
		}

		public function processGetBody($Value)
		{
			if(!is_array($Value))
			{				$Value = array($Value);
			}
			$params = $this->_prepareSettings('bodyPrepend', 'bodyAppend');
			if($params->bodyPrepend)
			{				array_unshift($Value, $params->bodyPrepend);
			}
			if($params->bodyAppend)
			{
				array_push($Value, $params->bodyAppend);
			}
			return parent::processGetBody($Value);
		}
	}
